package com.detu.ivos.geofence.controller;

import com.detu.ivos.base.response.JsonResult;
import com.detu.ivos.geofence.pojo.dto.GeofenceQuery;
import com.detu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import com.detu.ivos.geofence.pojo.vo.GeofenceVO;
import com.detu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {
    @Autowired
    GeofenceService geofenceService;

    //查询围栏
    @GetMapping("select")
    public JsonResult selectGeofence(GeofenceQuery geofenceQuery){
        List<GeofenceVO> geofenceVOS = geofenceService.selectGeo(geofenceQuery);
        return JsonResult.ok(geofenceVOS);
    }
    //添加围栏
    @PostMapping("save")
    public JsonResult saveGeo(GeofenceSaveParam geofenceSaveParam){
        geofenceService.saveGeofence(geofenceSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("update/status/{GeoId}/{GeoStatus}")
    public JsonResult updateStatus(@PathVariable Long GeoId,@PathVariable String GeoStatus ){
        log.debug("更新的围栏id={},围栏状态={}",GeoId,GeoStatus);
        geofenceService.updateStatus(GeoId,GeoStatus);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteGeo(@PathVariable Long id){
        log.debug("删除围栏的id={}",id);
        geofenceService.deleteById(id);
        return  JsonResult.ok();
    }

}
